<?php
	
	class EventItemUserBusiness {
		
		public function selectEventItemAttendant($eventItem) {
			$dataBaseConnection = DataAccessFactory::factory('DataAccessMySQL');
			
			$dataBaseConnection->connect();
			
			$eventItemDataAccess = DataAccessFactory::factory('EventItemUserDataAccessMySQL');
			
			$result = $eventItemDataAccess->selectEventItemAttendant($eventItem, $dataBaseConnection);
			
			$dataBaseConnection->disconnect();
			return $result;
		}
		
		public function deleteEventItemAttendant($eventItem, $dataBaseConnection = null) {
			
			$connectionOpened = false;
			if ($dataBaseConnection == null) {
				$connectionOpened = true;
				$dataBaseConnection = DataAccessFactory::factory('DataAccessMySQL');
				$dataBaseConnection->connect();
				$dataBaseConnection->beginTransaction();
			}
			
			$eventItemMaterialBusiness = BusinessFactory::factory('EventItemMaterialBusiness');
			$result1 = $eventItemMaterialBusiness->deleteEventItemMaterialByEventItemAttendant($eventItem, $dataBaseConnection);
			
			$eventItemCommentBusiness = BusinessFactory::factory('EventItemCommentBusiness');
			$result2 = $eventItemCommentBusiness->deleteEventItemCommentByEventItemAttendant($eventItem, $dataBaseConnection);

			$eventItemUserDataAccess = DataAccessFactory::factory('EventItemUserDataAccessMySQL');
			$result = $eventItemUserDataAccess->deleteEventItemAttendant($eventItem, $dataBaseConnection);
			
			if ($connectionOpened) {
				if (!$result || !$result2 || !$result1) {
					$dataBaseConnection->rollback();
				} else {
					$dataBaseConnection->commit();
				}
				$dataBaseConnection->disconnect();
			}
			
			return $result;
		}
	}

?>